"""
测试财务添加付款单点击保存并新建
"""
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By

#打开浏览器
driver = webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(30)
#打开crm
driver.get("http://192.168.1.25/crm")
sleep(1)
#准备数据
username = "admin"
password = "123456"
fksj = '2023-03-29'
fkje = "666"
msnr = "科科欠款两百万"
#定位器
username_locator = (By.NAME,'name')
password_locator = (By.NAME,'password')
login_btn_locator = (By.NAME,'submit')
cw_locator = (By.LINK_TEXT,'财务')
fkd_locator = (By.LINK_TEXT,'付款单')
tj_ysk_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div:nth-child(1) > div.pull-right > a')
yfk_locator = (By.NAME,'payables')
xz_fsk_locator = (By.CSS_SELECTOR,'#data > tr:nth-child(1) > td:nth-child(1) > input[type=radio]')
xz_fsk_qd_locator = (By.CSS_SELECTOR,'body > div:nth-child(8) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1)')
fkje_locator = (By.ID,'money')
fksj_locator = (By.XPATH,'/html/body/div[5]/div[2]/div/form/table/tbody/tr[6]/td[2]/input')
dxk_wjz_locator = (By.NAME,'status')
msnr_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div > form > table > tbody > tr:nth-child(8) > td:nth-child(2) > textarea')
fkd_bcxj_btn_locator = (By.NAME,'submit')



#登录输入用户名和密码
driver.find_element(*username_locator).send_keys(username)
driver.find_element(*password_locator).send_keys(password)
sleep(1)
#点击登录
driver.find_element(*login_btn_locator).click()
sleep(1)
#点击财务
driver.find_element(*cw_locator).click()
sleep(1)
#点击付款单
driver.find_element(*fkd_locator).click()
sleep(1)
#点击新建
driver.find_element(*tj_ysk_locator).click()
sleep(1)
#输入付款单
driver.find_element(*yfk_locator).click()
driver.find_element(*xz_fsk_locator).click()
driver.find_element(*xz_fsk_qd_locator).click()
sleep(1)
#输入金额
driver.find_element(*fkje_locator).send_keys(fkje)
sleep(1)
# #选择收款时间
driver.find_element(*fksj_locator).send_keys(fksj)

sleep(2)
#状态未结账
driver.find_element(*dxk_wjz_locator).click()
#输入描述
driver.find_element(*msnr_locator).send_keys(msnr)
sleep(1)
#点击保存
driver.find_element(*fkd_bcxj_btn_locator).click()

#退出
sleep(2)
driver.quit()